/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-01-17
 * Time: 22:55
 */
class Main {
    public int kthToLast(ListNode head, int k) {
        if(k <= 0 || head == null) {
            return -1;
        }
        ListNode fast = head;
        ListNode slow = head;
        while(k-1 != 0) {
            fast = fast.next;
            if(fast == null) {
                return -1;
            }
            k--;
        }
        while(fast.next != null) {
            fast = fast.next;
            slow = slow.next;
        }
        return slow.val;
    }
}